//各种校验规则
//校验用户名字
export const validatorName = (rule: any, value: any, callBack: any) => {
  if (value.trim().length >= 5) {
    callBack();
  } else {
    callBack(new Error("用户名字至少五位", rule));
  }
};
//校验用户昵称
export const validatorNickName = (rule: any, value: any, callBack: any) => {
  if (value.trim().length >= 2) {
    callBack();
  } else {
    callBack(new Error("用户昵称至少两位", rule));
  }
};
//校验用户密码
export const validatorPassword = (rule: any, value: any, callBack: any) => {
  if (value.trim().length >= 6) {
    callBack();
  } else {
    callBack(new Error("用户密码至少六位", rule));
  }
};

//校验用户邮箱
export const validatorEmail = (rule: any, value: any, callBack: any) => {
  if (value === "") {
    callBack(new Error("请输入邮箱", rule));
  } else if (!/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(value)) {
    callBack(new Error("请输入正确的邮箱", rule));
  } else {
    callBack();
  }
};

//校验用户手机号
export const validatorMobile = (rule: any, value: any, callBack: any) => {
  if (value === "") {
    callBack(new Error("请输入手机号", rule));
  } else if (!/^1(3|4|5|6|7|8|9)[0-9]\d{8}$/.test(value)) {
    callBack(new Error("请输入正确的手机号", rule));
  } else {
    callBack();
  }
};

//校验角色名字
export const validatorRoleName = (rule: any, value: any, callBack: any) => {
  if (value.trim().length >= 2) {
    callBack();
  } else {
    callBack(new Error("用户名字至少两位", rule));
  }
};

//校验菜单名称
export const validatorMenuName = (rule: any, value: any, callBack: any) => {
  if (value.trim().length >= 2) {
    callBack();
  } else {
    callBack(new Error("菜单名称至少两位", rule));
  }
};

//校验名称
export const validatorNames = (rule: any, value: any, callBack: any) => {
  if (value.trim().length > 0) {
    callBack();
  } else {
    callBack(new Error("名称不能为空!", rule));
  }
};

//上级机构名称
export const validatorParentName = (rule: any, value: any, callBack: any) => {
  if (value.trim().length > 0) {
    callBack();
  } else {
    callBack(new Error("上级机构不能为空!", rule));
  }
};
